package com.logic.landseaserver.domain;

import java.sql.Timestamp;
import java.util.Date;

public class AnswerDetail {
    private Integer id;

    private Integer questionId;

    private Integer answerBasicId;

    private String answer;

    private Integer version;

    private Date createdDtm;

    private Integer createdBy;

    private Date lastModifiedDtm;

    private Integer lastModifiedBy;

    private Boolean deleted;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getQuestionId() {
        return questionId;
    }

    public void setQuestionId(Integer questionId) {
        this.questionId = questionId;
    }

    public Integer getAnswerBasicId() {
        return answerBasicId;
    }

    public void setAnswerBasicId(Integer answerBasicId) {
        this.answerBasicId = answerBasicId;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer == null ? null : answer.trim();
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Date getCreatedDtm() {
        return createdDtm;
    }

    public void setCreatedDtm(Date createdDtm) {
        this.createdDtm = createdDtm;
    }

    public Integer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Integer createdBy) {
        this.createdBy = createdBy;
    }

    public Date getLastModifiedDtm() {
        return lastModifiedDtm;
    }

    public void setLastModifiedDtm(Date lastModifiedDtm) {
        this.lastModifiedDtm = lastModifiedDtm;
    }

    public Integer getLastModifiedBy() {
        return lastModifiedBy;
    }

    public void setLastModifiedBy(Integer lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }
    
    public void updateCommonInfo(Integer userId) {

        Timestamp now = new Timestamp(new Date().getTime());
        if (this.getId() == null || this.getId() == 0) { // New PoJo
          this.setVersion(0);
          if (this.getCreatedDtm() == null) {
            this.setCreatedDtm(now);
          }
          if (this.getCreatedBy() == null || this.getCreatedBy().equals(0)) {
            this.setCreatedBy(userId == null ? 0 : userId);
          }
          this.setLastModifiedDtm(now);
          this.setLastModifiedBy(userId == null ? 0 : userId);
          this.setDeleted(false);

        } else { // Update this
          this.setVersion(this.getVersion() == null ? 1 : this.getVersion() + 1);
          this.setLastModifiedDtm(now);
          if (userId.equals(-1)) {
          } else {
            this.setLastModifiedBy(userId == null ? 0 : userId);
          }
        }
      }
    
}